(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.fi.viewController', viewController);
	viewController.$inject = [ '$scope', 'Constants', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'fiService' ];
	function viewController($scope, Constants, layoutConfig, validatorConfig, gridService, authService, fiService) {
		var ctrl = this, fiInfo = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.fi = {};
		ctrl.fiOld = {};
		ctrl.fi.fiCodeList = ctrl.fi.fiCodeList || [];
		ctrl.init = function() {
			var params = {
				fiId : fiInfo.fiId
			};
			ctrl.innerGridOptions = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.fiCode.tableConfigs.table);
			ctrl.innerGridOptions.data = 'vm.fi.fiCodeList';
			ctrl.innerGridOptions.enableRowHeaderSelection = false;
			
			fiService.initGeneral($scope, ctrl);
			
			return authService.view(params).then(function(response) {
				ctrl.fi = response.data || fiInfo;
			}, angular.noop);
		};
	}
})(angular);